<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>五星好评</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #first_box{
            width: 350px;
            height: 40px;
            margin: 0 auto;
        }
        span{
            cursor: pointer;
            color: #ccc;
        }
        .triangle_first{
            font-size: 40px;
        }

    </style>
</head>
<body>
    <div id="first_box">
        五星评价：
        <span class="triangle_first">★</span>
        <span class="triangle_first">★</span>
        <span class="triangle_first">★</span>
        <span class="triangle_first">★</span>
        <span class="triangle_first">★</span>
    </div>
</body>
<script>
    var str = document.getElementsByClassName("triangle_first");
    var len = str.length;
    document.getElementById("first_box").addEventListener("click",function (e) {
        for(var i = 0; i < len; i++){
            str[i].setAttribute("data-index",i);
            str[i].style.color = "#ccc";
        }
        var sum;
        e=event||window.event;
        if(e.target="i".toUpperCase()){
            sum = e.target.getAttribute("data-index");
        }
        for(var i = 0; i <= sum; i++){
            str[i].style.color = "orange";
        }
    })
</script>
</html>